import { Article } from '../articles/entities/article.entity';

export type ArticleWithLabelStrings = Omit<Article, 'tags' | 'category'> & {
  tags: string[];
  category: string;
};

/**
 * 将单个Article对象的tags和category转换为对应的标签和分类字符串。
 */
export function transformArticleToLabelStrings(article: Article): ArticleWithLabelStrings {
  return {
    ...article,
    tags: article.tags.map((tag) => tag.label),
    category: article.category ? article.category.tree : '',
  };
}

/**
 * 批量转换Article数组，将每个对象的tags和category转换为标签和分类字符串。
 */
export function transformArticlesToLabelStrings(articles: Article[]): ArticleWithLabelStrings[] {
  return articles.map(transformArticleToLabelStrings);
}
